package com.chen.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.chen.entity.Subject;
import com.chen.vo.SubjectVO;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 试题Mapper
 */
public interface SubjectMapper extends BaseMapper<Subject> {

    /**
     * 总试题数量
     * @return
     */
    default Long findAllCount() {
        return selectCount(Wrappers.lambdaQuery(Subject.class));
    }

    /**
     * 根据年级获取试题数量
     * @param gradeId
     * @return
     */
    default Long findCountByGradeId(Integer gradeId) {
        Wrapper<Subject> queryWrapper = Wrappers.lambdaQuery(Subject.class).eq(Subject::getGradeId, gradeId);
        return selectCount(queryWrapper);
    }

    /**
     * 更具科目查看考试计划个数
     * @param courseId
     * @return
     */
    default Long findCountByCourseId(Integer courseId) {
        Wrapper<Subject> queryWrapper = Wrappers.lambdaQuery(Subject.class).eq(Subject::getCourseId, courseId);
        return selectCount(queryWrapper);
    }

    /**
     * 分页获取试题列表信息
     * @param subjectId
     * @param courseId
     * @param gradeId
     * @param index
     * @param pageShow
     * @return
     */
    List<SubjectVO> pageList(@Param("subjectId") Integer subjectId, @Param("courseId") Integer courseId, @Param("gradeId") Integer gradeId, @Param("index") Integer index, @Param("pageShow") Integer pageShow);

    /**
     * 根据id获取试题信息
     * @param subjectId
     * @return
     */
    SubjectVO getSubjectById(@Param("subjectId") Integer subjectId);


    /**
     * 随机获取未被某试卷绑定的试题
     * @param examPaper 试卷id
     * @param courseId 课程id
     * @param gradeId 年级
     * @param easy 难度
     * @param subjectSum 数量
     * @return
     */
    List<SubjectVO> randomNotExamPaper(@Param("examPaper") Integer examPaper, @Param("courseId") Integer courseId, @Param("gradeId") Integer gradeId, @Param("easy") Integer easy, @Param("subjectSum") Integer subjectSum);

}
